// pages/download/download.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    imgSrc: ""
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {

  },

  /**
   * 
   */
  doDownload: function() {
    wx.downloadFile({
      url: 'http://47.112.201.202:8082/download?name=test2.pdf',
      success(res) {
        const filePath = res.tempFilePath
        console.log('下载文档成功,filePath: ' + filePath);
        wx.openDocument({
          filePath,
          success(res) {
            console.log('打开文档成功')
          }
        })
      }
    })
  },

  /**
   * 
   */
  doSaveFile: function() {
    let that = this

    wx.chooseImage({
      sourceType: ['camera'],
      success(res) {
        // tempFilePath可以作为img标签的src属性显示图片
        const tempFilePaths = res.tempFilePaths

        wx.saveFile({
          tempFilePath: tempFilePaths[0],
          success(res) {
            const savedFilePath = res.savedFilePath

            that.setData({
              imgSrc: savedFilePath
            })

            console.log(savedFilePath)
          }
        })

      }
    })
  },
})